﻿Public Class LoginForm

    Private Sub btExit_Click(sender As System.Object, e As System.EventArgs) Handles btExit.Click
        Application.Exit()
    End Sub


    Private Sub btLogin_Click(sender As System.Object, e As System.EventArgs) Handles btLogin.Click
        If txtUsername.Text.Trim().Length = 0 Then
            MessageBox.Show("Xin vui lòng nhập vào username")
            txtUsername.Focus()
            Return
        End If
        If txtPassword.Text.Trim().Length = 0 Then
            MessageBox.Show("Xin vui lòng nhập vào password")
            txtPassword.Focus()
            Return
        End If

        Dim dt As DataTable = UsersDAO.CheckUser(txtUsername.Text.Trim(), txtPassword.Text.Trim())
        If dt.Rows.Count > 0 Then
            txtUsername.Text = ""
            txtPassword.Text = ""
            Me.Hide()
            Dim user As New User
            user.MaUser = dt.Rows(0).Item("MaUser")
            user.username = dt.Rows(0).Item("username")
            user.Fullname = dt.Rows(0).Item("Fullname")
            user.QuyenHan = dt.Rows(0).Item("QuyenHan")
            'Phat sinh thu tien gui tiet kiem
            TietKiemBUS.PhatSinhThu(user.MaUser)
            'Phat sinh chi trả nợ
            QuanLyNoBus.PhatSinhChi(user.MaUser)

            MainForm.current_user = user
            MainForm.Show()
        Else
            MessageBox.Show("Username or password is error")
        End If
    End Sub
End Class